$(function () {
    $.ajax({
        type:'get',
        url:BigNew.user_detail,
        headers:{
            Authorization:window.localStorage.getItem('token')
        },
        success:function(backData){
            // console.log(backData);
            for(let key in backData.data){
                $('.'+key).val(backData.data[key])
                $('.user_pic').attr('src',backData.data.userPic)
            }
        }
    })
      //头像预览
      $('#exampleInputFile').on('change',function(){
        let file1 = this.files[0]
        let url1 = URL.createObjectURL(file1)
        $('.user_pic').attr('src',url1)
    })
    // 用户主页  编辑
    $('.btn-edit').on('click',function(e){
        e.preventDefault()
        let form1 = document.querySelector('form')
        let fd = new FormData(form1)
        // console.log(fd);
        
        $.ajax({
            type:'post',
            url: BigNew.user_edit,
            data: fd,
            contentType: false,
            processData: false,
            success: function (backData) {
                if (backData.code == 200) {
                    // console.log(backData);
                    alert('更新成功')
                    // parent.window.location.reload()
                    $.ajax({
                        type: 'get',
                        url: BigNew.user_info,
                        success: function (backData) {
                            console.log(backData);
                            if (backData.code == 200) {
                                parent.$('.user_info').find('img').attr('src',backData.data.userPic)
                                parent.$('.user_info').find('span').text(backData.data.nickname)
                                $('.user_center_link').find('img').attr('src',backData.data.userPic)
                            }
                        }
                    })
                }
            }
        })
    })
})